<template>
	<view class="container" :style="{ paddingTop: statusBarHeight + 'px' }">
		<uni-nav-bar leftIcon="left" left-text="返回" backgroundColor="#4d71f1" color="#ffffff" title="绩效考核"
		 @clickLeft="back" />		 
		 <uni-forms style="margin: 25rpx 25rpx;"  ref="baseForm" :model="baseFormData" :rules="customRules" labelWidth="80px">
			<uni-forms-item label="考核主题" >
				{{baseFormData.evaluationTitle}}
			</uni-forms-item>
			<uni-forms-item label="是否通过" required>
				<uni-data-checkbox v-model="baseFormData.fisSuccess" :disabled="readOnly" :localdata="isSuccess" />
			</uni-forms-item>
			<!-- <uni-forms-item label="考核得分" required name="money">
				<uni-easyinput v-model="baseFormData.performanceScore" placeholder="请输入奖励金额" />
			</uni-forms-item> -->
			<uni-forms-item label="评论备注" required name="comments">
				<uni-easyinput type="textarea" v-model="baseFormData.comments"  :disabled="readOnly" maxlength="125" placeholder="考核的附加评论或备注信息" />
			</uni-forms-item>			
		</uni-forms>
		<button type="primary" v-if="!readOnly" @click="submit('baseForm')">提交</button>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 状态栏高度
				statusBarHeight: 100,
				// 基础表单数据
				baseFormData: {
					resultId: 0,
					evaluationTitle: null,
					fisSuccess: null,					 
					comments: '',
					//createDateTime: '',
					personIds: '',
					id: null,
				},
				readOnly: false,
				evaluationTitle: "",
				// 单选数据源
				isSuccess: [{
					text: '不通过',
					value: 0
				}, {
					text: '通过',
					value: 1
				}],
				// 自定义表单校验规则
				customRules: {
					comments: {
						rules: [{
							required: true,
							errorMessage: '评论/备注不能为空'
						}]
					},
					money: {
						rules: [{
							format: 'number',
							errorMessage: '只能输入数字'
						}]
					}						

				},
			}
		},
		onLoad(options) {
			console.log('考核页面获取到的id参数为:', options);
			try{
				this.baseFormData.id = options.id;
				if(typeof(options.pid)!="undefined"){
					this.baseFormData.personIds = options.pid;
				}
				if(typeof(options.title)!="undefined"){					
					this.evaluationTitle=options.title
					this.baseFormData.evaluationTitle=options.title
				}
				if(typeof(options.type)!="undefined" &&options.type==="doEvaluation"){
					return;
				}else{
					console.log('getDetail:', options.type);
					this.getDetail();
				}
			}catch (error) {
				console.error('请求失败:', error);
			}
		},
		mounted() {
			// 获取设备信息
			const systemInfo = uni.getSystemInfoSync();
			this.statusBarHeight = systemInfo.statusBarHeight; // 获取状态栏高度
		},
		methods: {
			getDetail(){				
				this.$myRequest.getRequest("/api/Performance/performanceResults/detail/"+this.baseFormData.id, null).then(res => {
					console.log('考核页面详情返回结果->', res);
					this.baseFormData = res.data;
					this.baseFormData.evaluationTitle = this.evaluationTitle;
					this.readOnly = true;
				}).catch(res => { 
					console.log('详情返回出错->', res);
				})
			},
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
			saveback() {				
				uni.navigateBack({
					delta: 1,
					success() {
					    uni.$emit('update:evaluation',{msg:'页面更新'})
					}
					
				})
			},
			submit(ref) {
				// this.saveback();return;
				console.log("提交",this.baseFormData);
				if (this.$kdup.isEmpty(this.baseFormData.comments.trim())) {
					uni.showToast({
						title: "评论/备注不能为空!",
						icon: "none",
						duration: 1000
					});
					return;
				}
				if (this.baseFormData.fisSuccess==null) {
					uni.showToast({
						title: "请选择考核是否通过!",
						icon: "none",
						duration: 1000
					});
					return;
				}
				this.$modal.confirm('确定提交绩效考核单吗？').then(() => {
					uni.showLoading({title: '提交中',mask:true});
					this.$myRequest.postRequest("/api/Performance/PerformanceResults", this.baseFormData).then(res => {
						setTimeout(function () {uni.hideLoading();}, 100);
						console.log('返回->', res);
						if (res.data.code===-1){
							uni.showToast({
								title: '绩效考核提交有问题！',
								icon: "none",
								duration: 1000
							});
							return;
						}
						this.saveback();						
					}); 
				})
			},
		}
	}
</script>

<style>
	.container {
		padding: 0px;
		background-color: #fff;
	}
	.form-item {
		display: flex;
		align-items: center;
		flex: 1;
	}

</style>
